import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:model_api_test/widget/custom_text_field.dart';

import 'logic.dart';

class HomePage extends StatelessWidget {
  const HomePage({super.key});

  @override
  Widget build(BuildContext context) {
    final HomeLogic logic = Get.find<HomeLogic>();
    final state = logic.state;
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Theme.of(context).colorScheme.inversePrimary,
        actions: [
          IconButton(
            icon: const Icon(Icons.refresh),
            tooltip: '检查服务',
            onPressed: () => logic.checkService(),
          ),
        ],
      ),
      body: Padding(
        padding: const EdgeInsets.all(16),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.stretch,
          children: [
            const Text(
              '接口测试面板',
              style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
            ),
            const SizedBox(height: 8),
            Row(
              children: [
                Expanded(
                  child: ElevatedButton(
                    onPressed: () => logic.checkService(),
                    child: const Text('测试 GET / (服务状态)'),
                  ),
                ),
                const SizedBox(width: 12),
                Expanded(
                  child: ElevatedButton.icon(
                    icon: const Icon(Icons.audiotrack),
                    label: Text('使用 mp3.mp3（原始字节上传）'),
                    onPressed: () => logic.transcribeFromAssetWavPureDart(),
                  )
                ),
              ],
            ),
            const SizedBox(height: 8),
            Obx(
              () => CustomTextField(
                value: logic.segmentIndexInput.value,
                keyboardType: TextInputType.number,
                onChanged: (v) => logic.segmentIndexInput.value = v,
              ),
            ),
            const SizedBox(height: 12),
            Obx(() => Text(state.statusMessage.value)),
          ],
        ),
      ),
    );
  }
}
